<!-- #include file="conectar.asp" -->
<%
AbreBanco()
response.expires=0
Response.Charset = "ISO-8859-1"
'Response.Charset = "UTF-8"
set rs = server.createobject("ADODB.Recordset") 
if request("tipo") = "munic" then
	rs.open "SELECT Tb_Municipio.Cd_Municipio, Tb_Municipio.Ds_Municipio, Tb_Municipio.Cd_Grupo FROM Tb_MunicipioxProjeto inner join Tb_Municipio on " &_
		"Tb_MunicipioxProjeto.Cd_Municipio = Tb_Municipio.Cd_Municipio where Tb_MunicipioxProjeto.Cd_Projeto = " & request("parm") & " order by" &_
		" Tb_Municipio.Ds_Municipio",banco,3,3
	response.write "<select name='lst_disp' style='width:300px' size='16'>"			
	while not rs.eof
		response.write "<option value='" & rs(0) & "*" & rs(2) & "'>" & ucase(rs(1)) & "</option>"
		rs.movenext
	wend		
	response.write "</select>"								
elseif request("tipo") = "feriado" then
	if isdate(request("parm")) then
		rs.open "select * from tb_feriado where dt_feriado='" & left(request("parm"),5) & "'",banco,3,3
		if rs.eof then response.Write("0") else response.Write("1") end if		
	else
		response.Write("0")
	end if
elseif request("tipo") = "empenho" then
'	rs.open "select Nr_Empenho,Nr_Processo,Cd_Conta,Dt_Pagamento FROM Tb_Diaria WHERE cd_diaria=" & request("parm"),banco,3,3
	rs.open "SELECT Tb_Diaria.Nr_Empenho,Tb_Diaria.Nr_Processo,Tb_Diaria.Cd_Conta,Tb_Diaria.Dt_Pagamento,Bd_Pessoal..tb_colaborador.nm_colaborador FROM Tb_Diaria " &_
		  "INNER JOIN Bd_Pessoal..tb_colaborador ON Tb_Diaria.Cd_AutorEmpenho=Bd_Pessoal..tb_colaborador.cod_colaborador WHERE cd_diaria=" & request("parm"),banco,3,3
	'Para ser usado sem JSON
	response.Write rs(0) & "|" & left(rs(1),13) & "|" & rs(2) & "|" & rs(3) & "|" & rs(4)
	'Para ser usado com JSON
'	response.Write "Retorno:{'Empenho':'" & rs(0) & "','Processo':'" & rs(1) & "','Conta':'" & rs(2) & "','Data':'" & rs(3) & "'}"
elseif request("tipo") = "territ" then
	if request("parm") = "50" then
		rs.open "select cd_municipio,ds_municipio,estado from tb_municipio where (cd_territorio<>0) and (cd_municipio not in (select cd_municipio from tb_municipioxprojeto" &_
				" where cd_projeto=" & request("cd") & ")) order by ds_municipio",banco,3,3
	else
		rs.open "select cd_municipio,ds_municipio,estado from tb_municipio where (cd_territorio=" & request("parm") &_
				") and (cd_municipio not in (select cd_municipio from tb_municipioxprojeto where cd_projeto=" & request("cd") & ")) order by ds_municipio",banco,3,3
	end if
	response.write "<select name='lst_disp' size='16' style='width:90%' ondblclick='Seleciona(document.formulario.lst_disp,document.formulario.elements[4],true)'>"			
	while not rs.eof
		response.write "<option value='" & rs(0) & "'>" & ucase(rs(1)) & "-" & rs(2) & "</option>"
		rs.movenext
	wend		
	response.write "</select>"
elseif request("tipo") = "cpf" then
	rs.open "SELECT nome_Beneficiario,setor.des_setor FROM dbo.Tb_Beneficiario INNER JOIN Bd_Pessoal.dbo.tb_setor setor ON dbo.Tb_Beneficiario.Cd_Setor="&_
			"setor.cod_setor WHERE dbo.Tb_Beneficiario.CPF_Beneficiario='" & request("parm") & "'",banco,3,3
	if rs.eof then
		response.Write "Retorno:{'nome':'','setor':''}"
	else
		response.Write "Retorno:{'nome':'" & rs(0) & "','setor':'" & rs(1) & "'}"	
	end if
elseif request("tipo") = "processo" then
	rs.open "select count(*) as qtd from Bd_Sisproc..Tb_Processo where Protocolo='" & request("parm") & "00'",banco,3,3
	if rs(0)=0 then
		response.Write "999"
	else
		rs.close()
		rs.open "select CAST(Sequencial AS varchar) + '/' + CAST(YEAR(Dt_Solicitacao) AS varchar) AS numero from Tb_Diaria where nr_processo='" & request("parm") & "00'",banco,3,3		
		if rs.eof then
			response.write "NAS"
		else
			response.write rs(0)
		end if
	end if
elseif request("tipo") = "sel-solicitacao" then
	rs.open "select cd_diaria,nome_beneficiario,partida_pr,dt_pagamento,sequencial,year(partida_pr) as ano from tb_diaria inner join tb_beneficiario " &_
		"on tb_diaria.cd_beneficiario=tb_beneficiario.cd_beneficiario where ativa=1 and solicitacao_validada=1 and Tb_Beneficiario." &_
		"Nome_Beneficiario LIKE '%" & request("parm") & "%' order by cd_diaria desc",banco,3,3
	response.write "<select id='lst_diaria' style='width:710px' size='10' ondblclick='Ver(document.form.lst_diaria)'>"			
	while not rs.eof
		if isnull(rs(3)) then
			response.write "<option value='" & rs(0) & "'>* " & rs(4) & "/" & rs(5) & " - " & rs(1) & " - " & left(rs(2),16) & "</option>"	
		else
			response.write "<option value='" & rs(0) & "'> " & rs(4) & "/" & rs(5) & " - " & rs(1) & " - " & left(rs(2),16) & "</option>"
		end if
		rs.movenext
	wend
	response.write "</select>"
elseif request("tipo") = "sel-comprovacao" then
	rs.open "select cd_diaria,nome_beneficiario,chegada_ef,finalizada,sequencial,year(partida_pr) as ano from tb_diaria inner join tb_beneficiario " &_
			"on tb_diaria.cd_beneficiario=tb_beneficiario.cd_beneficiario where ativa=1 and comprovacao_validada=1 and Tb_Beneficiario.Nome" &_
			"_Beneficiario LIKE '%" & request("parm") & "%' order by cd_diaria desc",banco,3,3
	response.write "<select id='lst_diaria' style='width:710px' size='10' ondblclick='Ver(document.form.lst_diaria)'>"			
	while not rs.eof
		if rs(3) then
			response.write "<option value='" & rs(0) & "'> " & rs(4) & "/" & rs(5) & " - " & rs(1) & " - " & left(rs(2),16) & "</option>"
		else
			response.write "<option value='" & rs(0) & "'>* " & rs(4) & "/" & rs(5) & " - " & rs(1) & " - " & left(rs(2),16) & "</option>"
		end if
		rs.movenext
	wend
	response.write "</select>"
elseif request("tipo") = "finalizacao" then
	rs.open "SELECT Valor_Pr * Qtd_Pr - Valor_Ef * Qtd_Ef AS valor FROM dbo.Tb_Diaria where cd_diaria=" & request("parm"),banco,3,3
	response.write rs(0)
end if
rs.close()
FechaBanco()
%>
